package cn.impl;

import cn.annotation.Log;
import cn.basic.HibBaseDAOImpl;
import cn.basic.iHibBaseDAO;
import cn.common.properties.LogOperType;
import cn.dao.RoleSystemModelDAO;
import cn.model.TRoleSystemModel;
import cn.model.VRoleSystemModel;
import org.springframework.stereotype.Component;

import java.util.List;

@Component("rolesystemmodel")
public class RoleSystemModelDAOImpl implements RoleSystemModelDAO {
    private iHibBaseDAO bdao = null;

    public RoleSystemModelDAOImpl(){
        bdao = new HibBaseDAOImpl();
    }

    @Log(isSaveLog=true,operationType= LogOperType.ADD,operationName="添加角色菜单信息")
    @Override
    public int addRoleSystemModel(TRoleSystemModel RoleSystemModel) {
        return (Integer) bdao.insert(RoleSystemModel);
    }

    @Log(isSaveLog=true,operationType= LogOperType.DELETE,operationName="删除角色菜单信息")
    @Override
    public boolean deleteRoleSystemModel(int id) {
        TRoleSystemModel TRoleSystemModel = (cn.model.TRoleSystemModel) bdao.findById(cn.model.TRoleSystemModel.class, id);
        return bdao.delete(TRoleSystemModel);
    }

    @Log(isSaveLog=true,operationType= LogOperType.MODIFY,operationName="修改角色菜单信息")
    @Override
    public boolean modifyRoleSystemModel(TRoleSystemModel RoleSystemModel) {
        return bdao.update(RoleSystemModel);
    }

    @Log(isSaveLog=false)
    @Override
    public TRoleSystemModel getRoleSystemModelById(int id) {
        return (TRoleSystemModel) bdao.findById(TRoleSystemModel.class, id);
    }

    @Log(isSaveLog=true,operationType= LogOperType.QUERY,operationName="查询角色菜单信息")
    @Override
    public List<VRoleSystemModel> getAllRoleSystemModelByPage(int currentPage, int pageSize) {
        String hql = "from VRoleSystemModel order by parentid,displayorder asc";
        return bdao.selectByPage(hql, currentPage, pageSize);
    }

    @Log(isSaveLog=true,operationType= LogOperType.QUERY,operationName="查询角色菜单数量")
    @Override
    public int getAllVRoleSystemModelPageAmount() {
        String hql = "select count(*) from VRoleSystemModel";
        return bdao.selectValue(hql);
    }
}
